package hibernateDAOS;

import hibernate.HibernateUtil;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;


import beans.CajaCierre;
import beans.MedioPago;

public class CajaCierreDAO {
	
	private static CajaCierreDAO instancia = null;
	private static SessionFactory sf = null;

	public static CajaCierreDAO getInstancia(){
		if(instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new CajaCierreDAO();
		} 
		return instancia;
	}
	
	public void guardarCajaCierre(CajaCierre cc){
		Session session = sf.openSession();
		session.beginTransaction();
		session.save(cc);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public void eliminarCajaCierre(CajaCierre cc){
		Session session = sf.openSession();
		session.beginTransaction();
		session.delete(cc);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public void modificarCajaCierre(CajaCierre cc){
		Session session = sf.openSession();
		session.beginTransaction();
		session.saveOrUpdate(cc);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	@SuppressWarnings("unchecked")
	public List<CajaCierre> obtenerCajaCierre(){
		Session session = sf.openSession();
		Query q = session.createQuery("from CajaCierre");
		List<CajaCierre> ccs = q.list();
		session.close();
		return ccs;
	}
}




